const path = require("path");
const resolve = (dir) => path.join(__dirname, dir);
const minify =
  process.env.NODE_ENV === "development"
    ? false
    : {
        collapseWhitespace: true,
        removeComments: true,
        removeRedundantAttributes: true,
        removeScriptTypeAttributes: true,
        removeStyleLinkTypeAttributes: true,
        useShortDoctype: true,
        minifyCSS: true,
        minifyJS: true,
      };
module.exports = {
  runtimeCompiler: true,
  pages: {
    index: {
      entry: "src/main.js",
      template: "public/index.html",
      filename: "index.html",
      chunks: ["chunk-vendors", "chunk-common", "index"],
      minify,
    },
    preview: {
      entry: "src/views/preview/main.js",
      template: "public/preview.html",
      filename: "preview.html",
      chunks: ["chunk-vendors", "chunk-common", "preview"],
      minify,
    },
  },
  chainWebpack: (config) => {
    config.module.rule("svg").exclude.add(resolve("src/icons/svg")).end();
    config.module
      .rule("icons")
      .test(/\.svg$/)
      .include.add(resolve("src/icons/svg"))
      .end()
      .use("svg-sprite-loader")
      .loader("svg-sprite-loader")
      .options({ symbolId: "icon-[name]" })
      .end();
  },
  css: {
    loaderOptions: {
      sass: {
        prependData: '@import "@/style/_index.scss";',
      },
    },
  },
  lintOnSave: false,
  devServer: {
    overlay: {
      warning: false,
      errors: false,
    },
  },
};
